<?php
/**
 * Classe permettant de simplifié la gestion des erreurs
 *
 * @author Gaetan Collaud
 */
abstract class Log {
	const LOGLVL_ERR	= 1;
	const LOGLVL_WARN	= 3;
	const LOGLVL_NOTICE	= 5;
	const LOGLVL_DEBUG	= 7;
	const LOGLVL_INFOS	= 8;
	const LOGLVL_SQL	= 9;

	const LOG_FILE = 'log.txt';

	private static $dispMsg = false;

	private static $logLevel = 1;

	public static function err($method, $msg){
		self::enregistre($method, $msg, self::LOGLVL_ERR);
	}

	public static function warn($method, $msg){
		self::enregistre($method, $msg, self::LOGLVL_WARN);
	}

	public static function notice($method, $msg){
		self::enregistre($method, $msg, self::LOGLVL_NOTICE);
	}

	public static function debug($method, $msg){
		self::enregistre($method, $msg, self::LOGLVL_DEBUG);
	}

	public static function infos($method, $msg){
		self::enregistre($method, $msg, self::LOGLVL_INFOS);
	}

	public static function sql($method, $msg){
		self::enregistre($method, $msg, self::LOGLVL_SQL);
	}

	private static function enregistre($method, $msg, $type){
		if($type<=self::$logLevel){
			$e = date('d-m-y H:i:s')."\t".$method."\t".$msg;
			if(self::$dispMsg) echo '<hr /><br />'.$e.'<br /><hr />';
			self::writeMsg($e);
		}
	}

	private static function writeMsg($t){
		$p = @file_get_contents(ABS_DIR.self::LOG_FILE);
		@file_put_contents(ABS_DIR.self::LOG_FILE, $p."\n".$t);
	}

	public static function setLogLevel($l){
		self::$logLevel = $l;
	}

	public static function dispMsg(){
		self::$dispMsg = true;
	}

}
?>
